1374. 生成每种字符都是奇数个的字符串
为保证权益,题目请参考 1374. 生成每种字符都是奇数个的字符串(From LeetCode).
解决方案1
Python
python
# 1374. 生成每种字符都是奇数个的字符串
# https://leetcode.cn/problems/generate-a-string-with-characters-that-have-odd-counts/
class Solution:
def generateTheString(self, n: int) -> str:
if n == 1:
return "a"
elif n % 2 == 0:
return "a" * (n - 1) + "b"
elif n % 2 == 1:
return "a" * n
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12